﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using xhim.common.Api;
using xhim.common.Helper;

namespace xhim.client.update_service
{
    internal static class PlatformApiService
    {
        private static string _serverUrl = "";

        static PlatformApiService()
        {
            _serverUrl = ConfigurationManager.AppSettings["platform-url"].ToString();
        }
        #region client api
        public static string getVersion()
        {
            string url = _serverUrl + "/ec/client/version";
            Dictionary<string, object> parameter = new Dictionary<string, object>();

            ApiResultModel resultModel = ApiHelper.doPost(url, buidSignHeaders(parameter), parameter);
            if (resultModel.isSuccess)
            {
                return resultModel.data.ToString();
            }

            return "";
        }
        #endregion
        private static Dictionary<string, object> buidSignHeaders(Dictionary<string, object> data)
        {
            Dictionary<string, object> headers = new Dictionary<string, object>();
            string appKey = ConfigurationManager.AppSettings["sn"].ToString();
            string timestamp = SignHelper.getTimeStamp();
            string sign = SignHelper.getSign(appKey, appKey, timestamp, data);
            string nonce = System.Guid.NewGuid().ToString("N");
            headers.Add("appKey", appKey);
            headers.Add("timestamp", timestamp);
            headers.Add("nonce", nonce);
            headers.Add("sign", sign);
            return headers;
        }

    }
}
